/*******************************************************************************
 * Copyright (c) 2004, 2009 Blue Bamboo International Inc. 
 * All rights reserved.
 *
 * Blue Bamboo PROPRIETARY/CONFIDENTIAL.
 *******************************************************************************/

package com.bambamboo.st.serial.server.mina;

import org.apache.mina.transport.serial.SerialAddress;
import org.apache.mina.transport.serial.SerialConnector;

import com.bambamboo.st.AbstractIOServer;
import com.bambamboo.st.serial.server.SerialConnectionBean;
import com.bambamboo.st.socket.server.mina.AbstractIoHandler;
import com.bambamboo.st.socket.server.mina.DefaultIoHandler;

/**
 * Serial Listener implemented with Apache MINA.
 * <p>
 * Listen serial port and delegate all request to <code>IProecess</code>
 * </p>
 * 
 * @author Nick.Tan
 * @since 2.0.0
 */
public class SerialServer extends AbstractIOServer {

	@Override
	public void startup() throws Exception {
		SerialConnector connector = new SerialConnector();
		SerialConnectionBean bean = (SerialConnectionBean) getConnectionBean();
		AbstractIoHandler iohandler = new DefaultIoHandler();
		iohandler.setConfigurationBean(bean);
		connector.setHandler(iohandler);
		SerialAddress address = bean.toSerialAddress();
		connector.connect(address);
	}

	@Override
	public String getType() {
		return "Serial";
	}
}
